package com.example.onlyone;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import android.R.bool;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PlayActivity extends Activity {
	private TextView mTxView = null;
	private int width;
	private int height;
	private int iwidth;
	private int iheight;
	private LinearLayout centerlayout;
	private List<ViewCell> lists = new ArrayList<ViewCell>();
	public static HashMap<Integer, Integer> mLevelMap = new HashMap<Integer, Integer>();
	private int[][] arrays = new int[6][5];
	public PlayActivity() {
		
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
		Display dp = wm.getDefaultDisplay();
		DisplayMetrics outMetrics = new DisplayMetrics();
		dp.getMetrics(outMetrics);
		width = outMetrics.widthPixels;//dp.getWidth();
		height = outMetrics.heightPixels;//dp.getHeight();
		iwidth = width/5;
		iheight = iwidth;
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, width);
		centerlayout = new LinearLayout(this);
		centerlayout.setLayoutParams(params);
		centerlayout.setOrientation(LinearLayout.VERTICAL);
		centerlayout.setBackgroundColor(Color.WHITE);
		
		centerlayout.addView(getMainLayout());
		View mainView = View.inflate(this, R.layout.paly, null);
		centerlayout.addView(mainView);
		setContentView(centerlayout);
		
		//setContentView(R.layout.paly);
		mTxView = (TextView)findViewById(R.id.title);
		Intent intent = getIntent();
		String strName = intent.getStringExtra("number");
		mTxView.setText(strName);
		mTxView.setTextSize(40);
		SetLever();
	}
	
	private boolean SetLever() {
		Iterator iter = mLevelMap.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next();
			Integer key = (Integer)entry.getKey();
			Integer val = (Integer)entry.getValue();
			lists.get(key.intValue()).setNumber(val.intValue());
		}
		return true;
	}
	
	private View getMainLayout() {
		LinearLayout colLayout = new LinearLayout(this);
		colLayout.setOrientation(LinearLayout.VERTICAL);
		for(int i=0;i < 6;i++){
			colLayout.addView(getRowLayout());
		}
		return colLayout;
	}

	private View getRowLayout() {
		LinearLayout rowLayout = new LinearLayout(this);
		rowLayout.setOrientation(LinearLayout.HORIZONTAL);
//		rowLayout.setBackgroundColor(Color.GRAY);
		for(int i= 0 ;i < 5;i++){
			ViewCell viewcell = new ViewCell(this,iwidth,iheight);
			rowLayout.addView(viewcell);
//			viewcell.setNumber((int) Math.pow(2, testnumber));
//			testnumber++;
			lists.add(viewcell);
		}
		return rowLayout;
	}
}
